package com.apes.pi.model;

import com.apes.framework.api.SpringManager;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.pi.repository.PipeRepository;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 队列
 *
 * @author wuq
 * @create 2019-10-19 10:05
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PiQueue.CONST_TABLE_NAME)
public class PiQueue extends Model {
    public static final String CONST_TABLE_NAME = "pi_Queue";

    @Id
    @Column(name = "id", nullable = false, length = 30)
    @Comment("队列ID")
    private String id;

    @Column(name = "name", nullable = false, length = 200)
    @Comment("队列描述")
    private String name;   // 队列描述

    @Column(name = "type", nullable = false, length = 2)
    @Comment("传输模式（0:同步，1:异步）")
    private Integer type = 0;   // 传输模式（0:同步，1:异步）

    @Transient
    private List<Pipe> beforePipes;     // 前置拦截器

    @Transient
    private List<Pipe> afterPipes;      // 后置拦截器

    @Transient
    public String methodName() {
        return String.format("%s", id);
    }
}
